<template>
    <section class="k8s-logs">

        <el-row>

            <el-col :span="24" class="toolbr" style="padding-bottom: 0px;width: 100%">
                <el-form :inline="true" :model="logOptions" size="mini" border>
                    <el-form-item label="POD" >
                        <el-tag size="small">{{logOptions.podName}}</el-tag>
                    </el-form-item>
                    <el-form-item label="Container">
                        <el-select v-model="logOptions.CurrentContainerName" placeholder="请选择">
                            <el-option
                                    v-for="item in logOptions.containers"
                                    :key="item"
                                    :label="item"
                                    :value="item">
                            </el-option>
                        </el-select>

                    </el-form-item>
                </el-form>
            </el-col>
            <el-col :span="24" style="background-color: black">
                <el-input
                        type="textarea"
                        :autosize="{ minRows: 35, maxRows: 35}"
                        placeholder="所选容器没有日志信息或者遇到错误"

                        v-model="logOptions.Content"
                        readonly


                >
                </el-input>
            </el-col>
        </el-row>


    </section>
</template>

<script>
    import { k8sLogsData } from '../../api/api'
    export default {
        data() {
            return {
                logOptions: {
                    podName:"",
                    containers:[],
                    logLines:[],

                    Content:"",
                    CurrentContainerName:"",
                },

            }
        },
        methods: {

            getK8sPodLogs(){
                let self = this
                // let param = {name:podname,namespace:namespace}
                let param = {name:this.$route.params.name,namespace:this.$route.query.namespace}
                k8sLogsData(param).then((res) => {
                    console.log(res.logs)
                    self.logOptions.podName = res.logs.podName
                    self.logOptions.containers = res.logs.containers
                    self.logOptions.logLines = res.logs.logLines

                    self.logOptions.CurrentContainerName = res.logs.containers[0]
                    // self.logOptions.Content = res.logs.logLines
                    for (var log of res.logs.logLines){
                        self.logOptions.Content = self.logOptions.Content + log.content + "\n"
                    }

                })

            },

            lineBreak(str){
                return str.replace(/\n/gm,"<br/>")
            }

        },
        mounted: function () {
             this.getK8sPodLogs()
        }
    }
</script>
<!--scoped-->
<style >
    .minizisesize{
        -webkit-transform: scale(0.6) !important;
    }
    .eye-click:hover {
        cursor: pointer;
    }
    .k8s-logs .toolbr {
        border-radius:5px;
        border: 1px;
        /*background-color: gray;*/
    }
    .k8s-logs  .el-form--inline {
        height: 35px;
        /*background-color: gray;*/
        color: white;
        border: 1px;
    }
    .k8s-logs textarea {
        background-color: black !important;
        color: white;
    }

</style>